from widgetOrganizer import WidgetOrganizer
import gtk

class MainToolbar(WidgetOrganizer, gtk.HandleBox):
    def __init__(self, ancestor):
        gtk.HandleBox.__init__(self)
        WidgetOrganizer.__init__(self, 'MainToolbar', ancestor)

        child = Toolbar_File(self)
        self.addChild(child)
        self.add(child)
        
            
class Toolbar_File(WidgetOrganizer, gtk.Toolbar):
    def __init__(self, ancestor):
        gtk.Toolbar.__init__(self)
        WidgetOrganizer.__init__(self, 'Toolbar_File', ancestor)
        
        buttons = [['new', gtk.STOCK_NEW],
                   ['open', gtk.STOCK_OPEN],
                   ['save', gtk.STOCK_SAVE]]
        
        for label, stock in buttons:
            button = gtk.ToolButton(stock)
            button.show()
            item = gtk.ToolItem()
            item.add(button)
            item.show()
            button.connect('clicked',eval('self._event_'+label))
            self.insert(item, -1)
        
    def _event_new(self, widget):
        self.getAncestor('MainVBox').notebook.addWorksheet()
        
    def _event_open(self, widget):
        self.getAncestor('MainVBox').notebook.openWorksheet()
        
    def _event_save(self, widget):
        self.getAncestor('MainVBox').notebook.saveWorksheet()
